package main

import (
	"context"
	"fmt"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
	v1 "grpc-demo/api/product/v1"
	"time"
)

// 仅用于充当客户端，用于测试grpc-demo-server
func main() {
	conn, err := grpc.Dial("127.0.0.1:8080", grpc.WithTransportCredentials(insecure.NewCredentials()))
	if err != nil {
		fmt.Println(err)
		return
	}
	productClient := v1.NewProductClient(conn)

	go func() {
		for {
			time.Sleep(time.Second)
			product, err := productClient.AddProduct(context.Background(), &v1.AddProductReq{
				Name:        "12",
				Description: "34",
				Price:       12.34,
			})
			if err != nil {
				fmt.Println(err)
				return
			}
			fmt.Printf("%+v\n", product)
		}
	}()

	time.Sleep(100 * time.Second)
}
